package org.example;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

public class RedisListener extends JedisPubSub {
    @Override
    public void onPMessage(String pattern, String channel, String message) {
        System.out.println("Received message: " + message);
        // 处理接收到的事件消息
    }

    public static void main(String[] args) {
        // 创建 Jedis 实例并连接到 Redis 服务器
        Jedis jedis = new Jedis("localhost", 6379);
        System.out.println("Connected to Redis server.");

        // 订阅 key 新增和删除事件
        jedis.psubscribe(new RedisListener(), "__keyevent@0__:set", "__keyevent@0__:del");
    }
}